# Include the directory itself as a path to include directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Create a variable containing all .cpp files
file(GLOB core_SOURCES *.cpp)

# Create a variable containing all .h files
file(GLOB core_HEADERS *.h)

# Generate rules to copy over lua files as needed
file(GLOB core_LUA_SRCS *.lua)
copy_if_different( 
  "" "${EXECUTABLE_OUTPUT_PATH}/core"
  "${core_LUA_SRCS}" core_LUA_TGTS "Core Lua" 
)

# Create a library for this module
# (Include SLB since we expect its interfaces to be exposed)
add_library(core ${core_SOURCES} ${core_HEADERS} ${core_LUA_TGTS})

# Set up other dependencies
target_link_libraries(core ${CMAKE_DL_LIBS})

# Depends on SLB
if(slb_FOUND)
  add_definitions(${slb_DEFINITIONS})
  include_directories(${slb_INCLUDE_DIRS})
  target_link_libraries(core ${slb_LIBRARIES})
else()
  message(FATAL_ERROR "Unable to find SLB library.")
endif()

# Depends on PhysFS
if(physfs_FOUND)
  add_definitions(${physfs_DEFINITIONS})
  include_directories(${physfs_INCLUDE_DIRS})
  target_link_libraries(core ${physfs_LIBRARIES})
else()
  message(FATAL_ERROR "Unable to find PhysFS library.")
endif()

# Create core engine
add_executable(plinth-engine main.cpp)
target_link_libraries(plinth-engine core)

# Set up installation targets
install(FILES ${core_LUA_TGTS} DESTINATION bin/core)
